#include "Camera.h"

namespace TestDX
{

Camera::Camera() :
	_position(0.0f, 0.0f, 0.0f),
	_rotation(0.0f, 0.0f, 0.0f),
	_viewMatrix(1.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 1.0f, 0.0f,
				0.0f, 0.0f, 0.0f, 1.0f)
{
}

Camera::~Camera()
{
}

void Camera::Render()
{
	XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	XMVECTOR lookAt = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

	// Create rotation matrix
	// Uses: pitch (X axis), yaw (Y axis) and roll (Z axis) rotations in radians
	XMMATRIX rotationMatrix(XMMatrixRotationRollPitchYaw(_rotation.x * 0.0174532925f,
														 _rotation.y * 0.0174532925f,
														 _rotation.z * 0.0174532925f));

	// Transform lookAt and up by rotation matrix
	lookAt = XMVector3TransformCoord(lookAt, rotationMatrix);
	up = XMVector3TransformCoord(up, rotationMatrix);

	// Translate rotated camera to the location of the viewer
	XMVECTOR position = XMLoadFloat3(&_position);
	lookAt += position;

	// Create view matrix from updated vectors
	XMStoreFloat4x4(&_viewMatrix, XMMatrixLookAtLH(position, lookAt, up));
}

}